﻿using System.Collections.Generic;
using System.Globalization;
using CkSoftware.GroupMe.Sdk.Core.Dao;

namespace CkSoftware.GroupMe.Sdk.Helpers.Emoji
{
	/// <summary>
	/// Provides methods for parsing <see cref="GroupMeEmojiImage" /> from <see cref="GroupMeEmojiDefinition" />.
	/// </summary>
	public static class GroupMeEmojiImageParser
	{
		/// <summary>
		/// The sprite-image url-format for the emojis. {0} parameter = pack-id.
		/// </summary>
		private const string EmojiSpriteImageUrlFormat = "https://powerups.s3.amazonaws.com/emoji/{0}/inline.xhdpi.40x40.png";

		/// <summary>
		/// Parses any emoji definitions into usable image definitions (for client-side output).
		/// </summary>
		/// <param name="emojiDefinitions">The definitions to parse.</param>
		/// <returns>The parsed image data.</returns>
		public static IEnumerable<GroupMeEmojiImage> ParseImages(IEnumerable<GroupMeEmojiDefinition> emojiDefinitions)
		{
			foreach (GroupMeEmojiDefinition emoji in emojiDefinitions)
			{
				string spriteUrl = string.Format(CultureInfo.CurrentCulture, EmojiSpriteImageUrlFormat, emoji.PackId);
				int topPosition = GroupMeEmojiImage.DefaultEmojiHeight*emoji.EmojiId;

				yield return new GroupMeEmojiImage {PackSpriteImageUrl = spriteUrl, TopPosition = topPosition, Definition = emoji};
			}
		}
	}
}